﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WorkflowManagement.Web.UI
{
    /// <summary>
    /// A base class for workflow managers. Provides common logic used by all workflow managers.
    /// </summary>
    [CLSCompliant(true)]
    [NonVisualControl]
    [PersistChildren(false)]
    [ParseChildren(true)]    
    public abstract class WorkflowManagerBase: Control
    {
        /// <summary>
        /// Initializes a new instance of <see cref="WorkflowManagerBase"/>.
        /// </summary>
        protected WorkflowManagerBase()
        {        
        }
        
        private WorkflowTriggerCollection triggers = new WorkflowTriggerCollection();

        /// <summary>
        /// Gets the workflow trigger collection.
        /// </summary>
        /// <value>A <see cref="WorkflowTriggerCollection">collection</see> of <see cref="WorkflowTrigger">triggers</see>.</value>
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public WorkflowTriggerCollection Triggers
        {
            get { return triggers; }
        }

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            triggers.Initialize(this);
        }
        
        internal abstract void ExecuteWorkflow(Type workflowType, Dictionary<string, object> parameters);
    }
}
